package com.lkd.handler;

import com.lkd.business.MsgHandler;
import com.lkd.business.Topic;
import com.lkd.config.TopicConfig;
import com.lkd.contract.SupplyContract;
import com.lkd.service.TaskService;
import com.lkd.utils.JsonUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;

@Slf4j
@Component
@Topic(TopicConfig.TASK_SUPPLY_TOPIC)
public class SupplyHandler implements MsgHandler {

    @Autowired
    private TaskService taskService;

    @Override
    public void process(String jsonMsg) {
        log.info("接收到补货工单消息=jsonMsg={}",jsonMsg);
        if(StringUtils.isBlank(jsonMsg)){
            return ;
        }
        try {
            SupplyContract contract = JsonUtil.getByJson(jsonMsg, SupplyContract.class);
            taskService.createSupplyAuto(contract);
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}
